package com.minis.web.test.controller;

import com.minis.beans.factory.annotation.Autowired;
import com.minis.web.bind.annotation.RequestMapping;
import com.minis.web.bind.annotation.ResponseBody;
import com.minis.web.test.entity.User;
import com.minis.web.test.service.AService;
import com.minis.web.test.service.BaseService;
import com.minis.web.test.service.IAction;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Date;

public class HelloWorldBean {
//    法一
//    public String doGet() {
//        return "hello world";
//    }
//    public String doPost() {
//        return "hello world";
//    }

    @RequestMapping("/test")
    public String doTest(String name) {
        return name;
    }

    @RequestMapping("/test1")
    public String doTest1(User user) {
        return user.getId() + " : " + user.getName() + " : " + user.getBirthday();
    }


//    localhost:8080/test2?name=bai&id=3&birthday=2024-10-24
    @RequestMapping("/test2")
    @ResponseBody
    public User doTest2(User user) {
        user.setName(user.name + "---");
        user.setBirthday(new Date());
        return user;
    }

    @Autowired
    AService aservice;

    @RequestMapping("/test4")
    public String testService(){
        System.out.println("aservice: " + aservice);
        aservice.sayHello();
        return "success";
    }

    @Autowired
    IAction action;  // 封装为 ProxyFactoryBean

    @RequestMapping("/testaop")
    public void doTestAop(HttpServletRequest request, HttpServletResponse response) {
        action.doAction();
    }

    // Pointcut：用一个模式通配方法名，例如 "do*"
    @RequestMapping("/testaop2")
    public void doTestAop2(HttpServletRequest request, HttpServletResponse response) {
        action.doAction();
        action.doSomething();
    }
}
